package com.hrms.hrms_employee.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hrms.common.vo.ResultMessage;
import com.hrms.hrms_employee.entity.StaffContract;
import com.hrms.hrms_employee.service.StaffContractService;
import com.hrms.hrms_employee.service.StaffProbationService;
import com.hrms.hrms_employee.vo.StaffProbationVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * 合同表(StaffContract)表控制层
 *
 * @author makejava
 * @since 2025-01-17 17:11:36
 */
@RestController
@RequestMapping("staffContract")
public class StaffContractController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private StaffContractService staffContractService;
    @Autowired
    private StaffProbationService probationService;

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param staffContract 查询实体
     * @return 所有数据
     */
    @GetMapping
    public R selectAll(Page<StaffContract> page, StaffContract staffContract) {
        return success(this.staffContractService.page(page, new QueryWrapper<>(staffContract)));
    }

    /**
     * 通过staffId查询合同信息
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResultMessage selectOne(@PathVariable Serializable id) {
        return new ResultMessage(ResultMessage.Success,"",this.staffContractService.selectBystaffId(id));
    }

    /**
     * 转正开启审批流程
     *
     * @param staffProbationVO 实体对象
     * @return 新增结果
     */
    @PostMapping
    public ResultMessage insert(@RequestBody StaffProbationVO staffProbationVO) {
        this.probationService.saveAndStartFlow(staffProbationVO);
        return new ResultMessage(ResultMessage.Success,"");
    }

    /**
     * 通过probationId查询转正信息
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/probation")
    public ResultMessage selectProbation(@RequestParam Serializable id) {
        return new ResultMessage(ResultMessage.Success,"",this.probationService.getBaseMapper().selectById(id));
    }

    /**
     * 修改数据
     *
     * @param staffContract 实体对象
     * @return 修改结果
     */
    @PutMapping
    public R update(@RequestBody StaffContract staffContract) {
        return success(this.staffContractService.updateById(staffContract));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public R delete(@RequestParam("idList") List<Long> idList) {
        return success(this.staffContractService.removeByIds(idList));
    }
}

